home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Tools - Objects / C++ / MPW C++ 3.1b1 / Examples / CPlusExamples / TDocument.cp < prev    next >
Text File  |  1989-09-29  |  4KB  |  152 lines

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Application Framework
  6. #
  7. #    CPlusAppLib
  8. #
  9. #    TDocument.cp    -    C++ source
  10. #
  11. #    Copyright © 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #            1.10                     07/89
  16. #            1.00                     04/89
  17. #
  18. #    Components:
  19. #            TApplicationCommon.h    July 9, 1989
  20. #            TApplication.h            July 9, 1989
  21. #            TDocument.h                July 9, 1989
  22. #            TApplication.cp            July 9, 1989
  23. #            TDocument.cp            July 9, 1989
  24. #            TApplication.r            July 9, 1989
  25. #
  26. #    CPlusAppLib is a rudimentary application framework
  27. #    for C++. The applications CPlusShapesApp and CPlusTESample
  28. #    are built using CPlusAppLib.
  29. #
  30. ------------------------------------------------------------------------------*/
  31.  
  32. /*
  33. Segmentation strategy:
  34.  
  35.     This program has only one segment, since the issues
  36.     surrounding segmentation within a class's methods have
  37.     not been investigated yet. We DO unload the data
  38.     initialization segment at startup time, which frees up
  39.     some memory 
  40.  
  41. SetPort strategy:
  42.  
  43.     Toolbox routines do not change the current port. In
  44.     spite of this, in this program we use a strategy of
  45.     calling SetPort whenever we want to draw or make calls
  46.     which depend on the current port. This makes us less
  47.     vulnerable to bugs in other software which might alter
  48.     the current port (such as the bug (feature?) in many
  49.     desk accessories which change the port on OpenDeskAcc).
  50.     Hopefully, this also makes the routines from this
  51.     program more self-contained, since they don't depend on
  52.     the current port setting. 
  53.  
  54. Clipboard strategy:
  55.  
  56.     This program does not maintain a private scrap.
  57.     Whenever a cut, copy, or paste occurs, we import/export
  58.     from the public scrap to TextEdit's scrap right away,
  59.     using the TEToScrap and TEFromScrap routines. If we did
  60.     use a private scrap, the import/export would be in the
  61.     activate/deactivate event and suspend/resume event
  62.     routines. 
  63. */
  64.  
  65. // Mac Includes
  66. #include <Types.h>
  67. #include <QuickDraw.h>
  68. #include <Fonts.h>
  69. #include <Events.h>
  70. #include <Controls.h>
  71. #include <Windows.h>
  72. #include <Menus.h>
  73. #include <TextEdit.h>
  74. #include <Dialogs.h>
  75. #include <Desk.h>
  76. #include <Scrap.h>
  77. #include <ToolUtils.h>
  78. #include <Memory.h>
  79. #include <SegLoad.h>
  80. #include <Files.h>
  81. #include <OSUtils.h>
  82. #include <Traps.h>
  83.  
  84. #include "TDocument.h"
  85.  
  86. TDocument::TDocument(short resID)
  87. {
  88.     fDocWindow = GetNewWindow(resID,nil,(WindowPtr) -1);
  89.     SetPort(fDocWindow);
  90. }
  91.  
  92. TDocument::~TDocument(void)
  93. {
  94.     DisposeWindow(fDocWindow);
  95. }
  96.  
  97. TDocumentLink::TDocumentLink(TDocumentLink *n, TDocument *v)
  98. {
  99.     fNext = n;
  100.     fDoc = v;
  101. }
  102.  
  103. TDocumentList::TDocumentList(void)
  104. {
  105.     fDocList = nil;
  106.     fNumDocs = 0;
  107. }
  108.  
  109. // find the TDocument associated with the window
  110. TDocument* TDocumentList::FindDoc(WindowPtr window)
  111. {
  112.     TDocumentLink* temp;
  113.     TDocument* tDoc;
  114.  
  115.     for (temp = fDocList; temp != nil; temp = temp->GetNext())
  116.       {
  117.         tDoc = temp->GetDoc();
  118.         if (tDoc->GetDocWindow() == window)
  119.           return tDoc;
  120.       }
  121.     return nil;
  122. }
  123.  
  124. // private list management routines
  125. void TDocumentList::AddDoc(TDocument* doc)
  126. {
  127.     TDocumentLink* temp;
  128.  
  129.     temp = new TDocumentLink(fDocList,doc);
  130.     fDocList = temp;
  131.     fNumDocs++;
  132. }
  133.  
  134. void TDocumentList::RemoveDoc(TDocument* doc)
  135. {
  136.     TDocumentLink* temp;
  137.     TDocumentLink* last;
  138.  
  139.     last = nil;
  140.     for (temp = fDocList; temp != nil; temp = temp->GetNext())
  141.       if (temp->GetDoc() == doc)
  142.         {
  143.           if (last == nil)                // if first item in list, just set first
  144.             fDocList = temp->GetNext();
  145.           else last->SetNext(temp->GetNext());
  146.           delete temp;                    // free the TDocumentLink
  147.           fNumDocs--;
  148.           return;
  149.         }
  150.       else last = temp;
  151. }
  152.